export { };
// 映射类型语法
// { readonly [P in K]?: T}

// { [P in K]: T}
// { [P in K]?: T}
// { [P in K]-?: T}
// { readonly [P in K]: T}
// { readonly [P in K] ?: T}
// { -readonly [P in K] ?: T}


// 映射类型示例
type Item = { a: string; b: number; c: boolean; };

type T1 = { [P in 'x' | 'y']: number }; // {x: number; y: number}
type T2 = { [P in 'x' | 'y']: P }; // {x: ‘x' ; y: 'y'}
type T3 = { [P in 'a' | 'b']: Item[P] }; // {a: string ; b: number}
type T4 = { [P in keyof Item]: Item[P] }; // {a: string ; b: number, c: boolean}


// myParital
// 工具类型
type MyParital<T> = {
  [P in keyof T]?: T[P]
};

type U1 = MyParital<{ name: string; age: number }>;// { name?: string; age?: number }




// key Mapping语法 其中的NewKeysType表示映射成的新key
type MappedTypeWidthNewKeys<T> = {
  [P in keyof T as NewKeysType]: T[P];
};

// 例子 -- Getter工具类型
// 功能：生成对象KV类型的getter函数类型
type Getter<T> = {
  [K in keyof T as `get${Capitalize<K & string>}`]: () => T[K];
};

interface User {
  name: string;
  age: number;
  choose: boolean;
};

type Getter1 = Getter<User>;
// {
//   getName: () => string;
//   getAge: () => number;
//   getChoose: () => boolean;
// }


// 例子 -- RemoveKindField工具类型
// 功能：去除某一个key类型
type Exclude<T, K> = T extends K ? never : T;
type RemoveKindField<T> = {
  [K in keyof T as Exclude<K, 'kind'>]: T[K];
};

interface User2 {
  name: string;
  age: number;
  kind: 'kind'
};

type User3 = RemoveKindField<User2>;// {name: string; age: number}